<?php
$this->placeholder("navegacion")->set($this->navegacion($this->nav));
$perfil = App_Perfil::getInstance();
$perfil->cargar("ADMIN_USUARIOS");
$this->placeholder( 'contenttab' )->captureStart();

$autoOpen="false"; //esto se utiliza al final de la pagina para determinar si se abre o no el dialog al iniciar
?>
<div id="dialog-form" title="Asignar programas" style="display:none;">
  <span id="form-container"></span>
</div>
<?php
if ($perfil->crear() && App_User::getCodigoPadreRol()== Roles_Model_Roles::CODPADRE_SEDE):
    $params=App_Util_SafeUrl::encriptar(array("accion"=>"crear"),true);

	?>
	<div align="right" class="buttons">
	  <a class="btn btn-primary link-asignar" href="<?php echo $this->baseUrl("usuarios/detalle/seleccionarprogramas/{$params}");?>">
	  <span class="glyphicon glyphicon-plus-sign"></span> Asignar programas</a>
	</div>
	<?php
endif;


if(count($this->datos)>0):
?>
<div id="DivContenedor">
<form action="<?=$this->baseUrl("/usuarios/detalle/guardardesasignarprogramas");?>" method="post">
<table id="table_id" align="center" class="iceDatTbl">
  <thead>
    <tr>
      <th width="10%">Código SNIES</th>
      <th width="50%">Nombre</th>
      <th width="16%">Ubicación</th>
      <th width="4%"><input type="checkbox" value="chk_" id="chk_Todos" name="chk_Todos"></th>
    </tr>
  </thead>
  <tbody>
	<?php foreach ($this->datos as $value):?>
    <tr>
      <td style="text-align:center;"><?php echo $value["codsnies"]?></td>
      <td><?php echo $value["nombreprograma"]?></td>
      <td><?php echo $value["ubicacion"]?></td>
      <td style="text-align:center;"><input type="checkbox" name="seleccionados[]" value="<?=$value["codprograma"];?>" /></td>
    </tr>
  <?php  endforeach;?>
  </tbody>
</table>
<div align="right"><input type="submit" value="Des-Asignar a usuario" class="btn btn-primary btn-sm" /></div>
</form>
</div>
<script type="text/javascript">
$(function() {
	var oTable = $('#table_id').dataTable({
		"bJQueryUI": true,
		"bAutoWidth": false,
 		"sPaginationType": "full_numbers",
 		"bStateSave": true,
 		"aoColumns": [	null,
 	 		 			null,
 	 		 			null,
 	 		 			{ "bSortable": false, "bSearchable": false }
 	 		 		 ]
 	 		  		
	});
	
	oTable.fnSetFilteringDelay();

});
</script>
<?php else:?>
<br/>
<?php echo $this->mensajes("No existen registros");?>
<?php endif;?>

<?php
$this->placeholder( 'contenttab' )->captureEnd();
$this->tabs->agregar_contenido("Asignar programas", $this->placeholder( 'contenttab' ));
echo $this->tabs->renderElement();
?>
<script type="text/javascript">
$(function() {
	$("#dialog-form").dialog({
		autoOpen: <?php echo $autoOpen;?>,
		height: 500,
		width: 800,
		modal: true,
		buttons: {
			'Cancelar': function() {
				$(this).dialog('close');
			}
		}
	});
	
	$('.link-asignar').click(function(e) {
		e.preventDefault();
		$("#form-container").load($(this).attr("href"), function(response, status, xhr) {
			$("#dialog-form").dialog("open");
		});
	});

});

$("#chk_Todos").change(function(){
	if($(this).is(":checked")) {
		$(this).closest('#DivContenedor').find('input[type=checkbox]').attr('checked', true);
	}else{
      	$(this).closest('#DivContenedor').find('input[type=checkbox]').attr('checked', false);
	}
});
</script>